﻿using System;
// if we implements a service without callback, then we will not depend on "system.servicemodel"
// but service with callback is highly coupled with "system.servicemodel"
using System.ServiceModel;

using WSU.Cheka.Duplex.Contracts;

namespace WSU.Cheka.Duplex.Services
{
    /// <summary>
    /// simulate a heavy calculation
    /// in each operation, sleep some a period of time to simulate heavy calculation
    /// </summary>
    public class CalculationSvc : ICalculation
    {
        public void Add(float x, float y)
        {
            IResultCallback callback = OperationContext.Current.GetCallbackChannel<IResultCallback>();
            callback.Display(x, y, "+", x + y);
        }

        public void Substract(float x, float y)
        {
            IResultCallback callback = OperationContext.Current.GetCallbackChannel<IResultCallback>();
            callback.Display(x, y, "-", x - y);
        }

        public void Multiple(float x, float y)
        {
            IResultCallback callback = OperationContext.Current.GetCallbackChannel<IResultCallback>();
            callback.Display(x, y, "*", x * y);
        }

        public void Divide(float x, float y)
        {
            IResultCallback callback = OperationContext.Current.GetCallbackChannel<IResultCallback>();
            callback.Display(x, y, "/", x / y);
        }
    }
}
